<?php

namespace App\Admin\Exceptions;

use App\Admin\Traits\ReponseJson;
use Exception;
use Illuminate\Http\Request;

/**
 * Class ValidationException
 * @package App\Exceptions
 */
class AdminException extends Exception
{
    /**
     * 所以驗證器相關的驗證異常
     */
    use ReponseJson;

    public function __construct($message = '', $code = 500, $jump = '')
    {
        $this->code    = $code;
        $this->message = $message;
        $this->jump    = $jump;
    }

    public function render(Request $request)
    {
        if ($request->expectsJson()) {
            return $this->failure($this->message, [], $this->code, $this->jump);
        }
        return view('admin.public.exception', ['code' => $this->code, 'message' => $this->message, 'jump' => $this->jump]);
    }
}
